import java.util.*;

public class Solution {
    public void printNumbers2(int n) {
        if (n <= 0) return;
        char[] arr = new char[n];
        for (int i = 0; i < 10; i++) {
            arr[0] = (char) ('0' + i);
            next(arr, 0);
        }
    }

    private void next(char[] arr, int i) {
        if (arr.length == i + 1) {
            System.out.println(Integer.parseInt(new String(arr)));
            return;
        }
        for (int j = 0; j < 10; j++) {
            arr[i + 1] = (char) ('0' + j);
            next(arr, i + 1);
        }
    }


    public int[] printNumbers1(int n) {
        if (n <= 0) return null;
        int[] res = new int[(int) Math.pow(10, n) - 1];
        char[] arr = new char[n];
        Arrays.fill(arr, '0');
        int i = 0;
        while (!increment(arr)) {
            res[i++] = Integer.parseInt(new String(arr));
        }
        return res;
    }

    private boolean increment(char[] arr) {
        boolean isOverflow = false;
        int taken = 0;
        for (int i = arr.length - 1; i >= 0; i--) {
            int sum = arr[i] - '0' + taken;
            if (i == arr.length - 1) {
                sum++;
            }
            if (sum >= 10) {
                if (i == 0) {
                    isOverflow = true;
                } else {
                    taken = 1;
                    arr[i] = (char) (sum - 10 + '0');
                }
            } else {
                arr[i] = (char) ('0' + sum);
                break;
            }
        }
        return isOverflow;
    }

    // 无意义的做法
    public int[] printNumbers0(int n) {
        int num = 1;
        for (int i = 0; i < n; i++) {
            num *= 10;
        }
        int[] res = new int[num - 1];
        for (int i = 0; i < num - 1; i++) {
            res[i] = i + 1;
        }
        return res;
    }

    public static void main(String[] args) {
        new Solution().printNumbers2(2);
    }
}
